package com.metaera.app.ui.adapters;

import android.content.Context;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.metaera.app.R;
import com.metaera.app.data.model.ArticleListResponse;
import com.metaera.app.data.model.CollectionListResponse;
import com.metaera.app.ui.activities.ArticleDetailsActivity;
import com.metaera.app.ui.activities.FlashNewsDetailsActivity;
import com.metaera.app.utils.DateUtils;
import com.metaera.app.utils.image.GlideApp;

import androidx.annotation.NonNull;

public class CollectionAdapter extends BaseQuickAdapter<CollectionListResponse, BaseViewHolder> {

    public CollectionAdapter() {
        super(R.layout.item_browsing_history);

        setOnItemClickListener((adapter, view, position) -> {
            Context context = view.getContext();
            CollectionListResponse item = getItem(position);
            context.startActivity(ArticleDetailsActivity.newInstance(context, item.getInformation_id()));
        });
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, CollectionListResponse item) {
        CollectionListResponse.Information information = item.getInformation();
        CollectionListResponse.Information.Author author = information.getAuthor();

        holder.setText(R.id.tv_article_title, information.getTitle())
                .setText(R.id.tv_article_author_date, String.format("%1s · %2s",
                                author.getNickname(),
//                                item.getCreate_time()
                        DateUtils.getTime(information.getRelease_time_stamp(), DateUtils.PATTERN_2)
                        )
                );

        // 封面图像
        ImageView ivArticleCover = holder.getView(R.id.iv_article_cover);
        GlideApp.with(ivArticleCover)
                .load(information.getPic())
                .miniThumb()
                .into(ivArticleCover);
    }

}
